package com.copm.demonstrationsystem.controller.introductionfeatures;

import com.copm.demonstrationsystem.commons.response.ResponseStatus;
import com.copm.demonstrationsystem.commons.util.ControllerUtils;
import com.copm.demonstrationsystem.service.introductionfeatures.CompanyDevelopHistoryService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: Yuan Baiyu
 * @Date: Created in 1:52 2018/4/25
 */
@RestController
@RequestMapping("/history")
@CrossOrigin
public class CompanyDevelopHistoryController {

    @Autowired
    CompanyDevelopHistoryService companyDevelopHistoryService;

    //获取“发展历程”页面所有信息（标题、内容、配图、开始日期、结束日期）
    @ApiOperation("发展历程页面的信息获取接口")
    @GetMapping
    ResponseStatus getPage() {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.getPage());
    }


    //删除“发展历程”页面 图片
    @ApiOperation("删除图片")
    @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是图片标识"
            , dataType = "Long", paramType = "path", required = true)
    @DeleteMapping("/image/{id}")
    ResponseStatus deleteCompanyDevelopHistoryImage(@PathVariable("id") Long id) {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.deleteCompanyDevelopHistoryImage(id));
    }


    //添加“发展历程”页面 图片
    @ApiOperation("添加图片")
    @ApiImplicitParams({@ApiImplicitParam(name = "file", value = "新的图片"
            , dataType = "file", paramType = "form", required = true),
            @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是图片标识"
                    , dataType = "Long", paramType = "path", required = true)})
    @PostMapping("/image/{id}")
    ResponseStatus addCompanyDevelopHistoryImage(@PathVariable("id") Long id, @RequestPart("file") MultipartFile file) {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.addCompanyDevelopHistoryImage(id, file));
    }

    //修改“发展历程”页面 标题文本
    @ApiOperation("修改标题文本")
    @ApiImplicitParams({@ApiImplicitParam(name = "title", value = "新的标题文本内容"
            , dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是文本标识"
                    , dataType = "Long", paramType = "path", required = true)})
    @PostMapping("/title/{id}")
    ResponseStatus modifyCompanyDevelopHistoryTitle(@PathVariable("id") Long id, @RequestParam(value = "title") String title) {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.modifyCompanyDevelopHistoryTitle(id, title));
    }

    //修改“发展历程”页面 内容文本
    @ApiOperation("修改内容文本")
    @ApiImplicitParams({@ApiImplicitParam(name = "content", value = "新的内容文本内容"
            , dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是文本标识"
                    , dataType = "Long", paramType = "path", required = true)})
    @PostMapping("/content/{id}")
    ResponseStatus modifyCompanyDevelopHistoryContent(@PathVariable("id") Long id, @RequestParam("content") String content) {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.modifyCompanyDevelopHistoryContent(id, content));
    }


    //修改“发展历程”页面 开始日期
    @ApiOperation("修改开始日期")
    @ApiImplicitParams({@ApiImplicitParam(name = "begin", value = "新的开始日期"
            , dataType = "Long", paramType = "query", required = true),
            @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是其它标识"
                    , dataType = "Long", paramType = "path", required = true)})
    @PostMapping("/begin/{id}")
    ResponseStatus modifyCompanyDevelopHistoryBeginTime(@PathVariable("id") Long id, @RequestParam("begin") Long begin) {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.modifyCompanyDevelopHistoryBeginTime(id, begin));
    }

    //修改“发展历程”页面 结束日期
    @ApiOperation("修改结束日期")
    @ApiImplicitParams({@ApiImplicitParam(name = "end", value = "新的结束日期"
            , dataType = "Long", paramType = "query", required = true),
            @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是其它标识"
                    , dataType = "Long", paramType = "path", required = true)})
    @PostMapping("/end/{id}")
    ResponseStatus modifyCompanyDevelopHistoryEndTime(@PathVariable("id") Long id, @RequestParam("end") Long end) {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.modifyCompanyDevelopHistoryEndTime(id, end));
    }

    //修改“发展历程”页面 图片
    @ApiOperation("修改图片")
    @ApiImplicitParams({@ApiImplicitParam(name = "file", value = "新的图片"
            , dataType = "file", paramType = "form", required = true),
            @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是图片标识"
                    , dataType = "Long", paramType = "path", required = true)})
    @PutMapping("/image/{id}")
    ResponseStatus modifyCompanyDevelopHistoryImage(@PathVariable("id") Long id, @RequestPart("file") MultipartFile file) {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.modifyCompanyDevelopHistoryImage(id, file));
    }

    //修改“项目介绍”页面图片信息
    @PostMapping("/background")
    @ApiOperation("修改背景图片")
    @ApiImplicitParam(name = "file", value = "新的图片"
            , dataType = "file", paramType = "form", required = true)
    public ResponseStatus modifyImage(@RequestPart("file") MultipartFile file){
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.modifyCompanyDevelopHistoryBackgroundImage(file));
    }

    //删除“发展历程”页面
    @ApiOperation("删除页面")
    @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是图片标识"
            , dataType = "Long", paramType = "path", required = true)
    @DeleteMapping("/{id}")
    ResponseStatus deleteCompanyDevelopHistory(@PathVariable("id") Long id) {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.deleteCompanyDevelopHistory(id));
    }


    //添加“发展历程”页面
    @ApiOperation("添加页面")
      @PostMapping()
    ResponseStatus addCompanyDevelopHistoryPage() {
        return ControllerUtils.fillResponse(new ResponseStatus(),
                companyDevelopHistoryService.addCompanyDevelopHistory());
    }

//
//    //删除“发展历程”页面 开始日期
//    @ApiOperation("删除开始日期")
//    @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是其它标识"
//            , dataType = "Long", paramType = "path", required = true)
//    @DeleteMapping("/begin/{id}")
//    ResponseStatus deleteCompanyDevelopHistoryBeginTime(@PathVariable("id") Long id) {
//        return ControllerUtils.fillResponse(new ResponseStatus(),
//                companyDevelopHistoryService.deleteCompanyDevelopHistoryBeginTime(id));
//    }
//
//    //删除“发展历程”页面 结束日期
//    @ApiOperation("删除结束日期")
//    @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是其它标识"
//            , dataType = "Long", paramType = "path", required = true)
//    @DeleteMapping("/end/{id}")
//    ResponseStatus deleteCompanyDevelopHistoryEndTime(@PathVariable("id") Long id) {
//        return ControllerUtils.fillResponse(new ResponseStatus(),
//                companyDevelopHistoryService.deleteCompanyDevelopHistoryEndTime(id));
//    }
//

//
//    //添加“发展历程”页面 开始日期
//    @ApiOperation("添加开始日期")
//    @ApiImplicitParams({@ApiImplicitParam(name = "begin", value = "新的开始日期"
//            , dataType = "Number", paramType = "query", required = true),
//            @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是其它标识"
//                    , dataType = "Long", paramType = "path", required = true)})
//    @PostMapping("/begindate/{id}")
//    ResponseStatus addCompanyDevelopHistoryBeginTime(@PathVariable("id") Long id, @RequestParam("begin") Date date) {
//        return ControllerUtils.fillResponse(new ResponseStatus(),
//                companyDevelopHistoryService.addCompanyDevelopHistoryBeginTime(id, date));
//    }
//
//    //添加“发展历程”页面 结束日期
//    @ApiOperation("添加结束日期")
//    @ApiImplicitParams({@ApiImplicitParam(name = "end", value = "新的结束日期"
//            , dataType = "Long", paramType = "query", required = true),
//            @ApiImplicitParam(name = "id", value = "请注意，ID是页面id（一页面一ID）,而不是其它标识"
//                    , dataType = "Long", paramType = "path", required = true)})
//    @PostMapping("/enddate/{id}")
//    ResponseStatus addCompanyDevelopHistoryEndTime(@PathVariable("id") Long id, @RequestParam("end") Date date) {
//        return ControllerUtils.fillResponse(new ResponseStatus(),
//                companyDevelopHistoryService.addCompanyDevelopHistoryEndTime(id, date));
//    }
//
//    @InitBinder
//    public void initBinder(WebDataBinder binder) {
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//        dateFormat.setLenient(false);
//        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
//    }
}
